<?php

namespace api\modules\v1\controllers;

use Yii;
use api\controllers\RestController;
use api\models\SignupForm;


/**
 * Default controller for the `v1` module
 */
class UserController extends RestController
{
    public $modelClass = 'api\modules\v1\services\User';

    /**
     * 重写create操作，进行用户注册或添加
     * @name: actions
     * @return array
     * @author: rickeryu <lhyfe1987@163.com>
     * @time: 17/11/21 下午4:57
     */
    public function actions() {
        $actions =  parent::actions(); // TODO: Change the autogenerated stub
        unset($actions['create']);
        return $actions;
    }

    /**
     * 添加用户的操作
     * @name: actionCreate
     * @return array
     * @author: rickeryu <lhyfe1987@163.com>
     * @time: 17/11/21 上午10:20
     */
    public function actionCreate(){
        $model = new SignupForm();
        $model->load(Yii::$app->getRequest()->getBodyParams(),'');
        if ($user = $model->signup()) {
            //创建用户成功，返回用户基本信息
            return $user;
        }
        $this->error($model);
    }

}
